package Volume1.ch9;

import java.util.Objects;

/**
 * @Auther jacob
 * @Date 2020/8/15 00:44
 */
public class Item implements Comparable<Item> {

    private String desc;
    private int partNumber;

    public Item(String desc, int partNumber) {
        this.desc = desc;
        this.partNumber = partNumber;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return "Item{" +
                "desc='" + desc + '\'' +
                ", partNumber=" + partNumber +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Item)) return false;
        Item item = (Item) o;
        return partNumber == item.partNumber &&
                Objects.equals(desc, item.desc);
    }

    @Override
    public int hashCode() {
        return Objects.hash(desc, partNumber);
    }


    @Override
    public int compareTo(Item o) {
        int diff = Integer.compare(partNumber, o.partNumber);
        return diff != 0 ? diff : desc.compareTo(o.desc);
    }
}
